﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietThuongLMS.ViewModels;
using VietThuongLMS.Utils;
using DCS.ComLib.Config;
using VietThuongLMS.Services;
using VietThuongLMS.Areas.Admin.Models;
using System.IO;

///Author: NHDuc 
namespace VietThuongLMS.Areas.Admin.Controllers
{
    public class LienHeController : Controller
    {
        [Authorize(Roles = "Admin,NhanVien")]
        public ActionResult Index()
        {
            if (!Request.IsAuthenticated)
                return RedirectToAction("Login", "Home", new { area = "Admin" });

            int page = 1;
            if (Request["p"] != null)
            {
                page = int.Parse(Request["p"].ToString());
            }

            LienHeViewModel LienHeList = LienHeService.GetLienHeList(int.Parse(ConfigReader.ReadString("ItemPerPage")), page);

            //phân trang
            Pagination pagination = new Pagination(true, Url.Content("~"), "Admin", "LienHe", "Index", "?p=", LienHeList.Total, page, int.Parse(ConfigReader.ReadString("ItemPerPage")), "Previous", "Next", "First", "End");
            string pageLinks = pagination.GetPageLinks();
            ViewData["pageLinks"] = pageLinks;
            //end phân trang

            return View(LienHeList);
        }

        [Authorize(Roles = "Admin,NhanVien")]
        public ActionResult Detail(int id)
        {
            LienHe LienHe = LienHeService.GetLienHeById(id);
            return View(LienHe);
        }

        [Authorize(Roles = "Admin,NhanVien")]
        [HttpGet]
        public ActionResult Delete(int id)
        {
            bool result = LienHeService.DeleteLienHe(id);
            if (result)
            {
                return RedirectToAction("Index", "LienHe", new { area = "Admin" });
            }
            else
            {
                return View();
            }

        }

    }
}
